#define  _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdlib.h>


#define LIST_INIT_SIZE 100
#define LISTINCREAMT 10

typedef int ElmeType;
typedef struct
{
	ElmeType* elme;
	int length;
	int size;
}SqList;

void InitList(SqList& L)
{
	L.elme = (ElmeType*)malloc(sizeof(ElmeType) * LIST_INIT_SIZE);
	if (L.elme == NULL)
		exit(-1);
	L.length = 0;
	L.size = LIST_INIT_SIZE;
}

void GetElme(SqList L, int i, ElmeType& e)
{
	if (i< 1 || i>L.length)
		return;
	e = L.elme[i - 1];
}


void Insert(SqList& L, int i, ElmeType e)
{
	if (i<1 || i>L.length + 1)
		return;
	if (L.length == L.size)
	{
		ElmeType* base = (ElmeType*)realloc(L.elme, sizeof(ElmeType) * (LIST_INIT_SIZE + LISTINCREAMT));
		if (!base)
			exit(-1);
		L.elme = base;
		L.size += LISTINCREAMT;
	}
	for (int j = L.length - 1; j >= i - 1; j--)
	{
		L.elme[j + 1] = L.elme[j];
	}
	L.elme[i-1] = e;
	L.length++;
}


void DeletLsit(SqList& L, int i, ElmeType e)
{
	if (i<1 || i>L.length)
		return;
	e = L.elme[i - 1];
	for (int j = i; j < L.length; j++)
	{
		L.elme[i - 1] = L.elme[i];
	}
	L.length--;
}

void Find(SqList L, ElmeType e, int& i)
{
	i = 1;
	while (i <= L.length && L.elme[i] != e)
		i++;
	if (i > L.length)
		i = 0;
}



